<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline" ref="form">
      <el-form-item label="用户名">
        <el-input v-model="listQuery.userName" />
      </el-form-item>
      <el-form-item label="导出时间 ">
        <div class="block">
          <el-date-picker
            v-model="value"
            @change="change"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </div>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="getList(1)">搜索</el-button>
      </el-form-item>
    </el-form>

    <mytable :data="list"  ref="table" @getList="getList" :listQuery="listQuery"  border style="width: 100%">
      <el-table-column prop="userName" label="用户名" align="center" width="200"></el-table-column>
       <el-table-column prop="userId" label="用户ID" align="center" ></el-table-column>
      <el-table-column prop="createTime" label="导出时间" align="center"></el-table-column>
      <el-table-column prop="filePath" label="文件下载路径" align="center"></el-table-column>
      <el-table-column prop="args" label="查询条件" align="center"></el-table-column>
      <el-table-column prop="progress" label="下载进度" align="center"></el-table-column>
      <el-table-column label="下载" align="center" width="200">
        <template slot-scope="scope">
        <el-button type="primary" v-if="scope.row.show"  @click.native="download(scope.row)" >下载</el-button>
        </template>
      </el-table-column>
    </mytable>
  </div>
</template>

<script>
import apidownloadLogQuery from "@/api/logManage/downloadLogQuery";
import mytable from "@/components/Table";
import apiexportLogs from "@/api/export/exportLogs";
export default {
  name: "downloadLog",
  components: {mytable},
  data() {
    return {
      list: [],
      listQuery: {
        userName: "", //用户名
        listLoading: true
      },
      value: []
    };
  },
  created() {
  },
  methods: {
    getList(pageNo) {
       this.listQuery.pageNo = pageNo || this.listQuery.pageNo;
       apidownloadLogQuery.getListDownloadLog(this.listQuery).then(res => {
        this.$refs.table.load(res.data.page.list, res.data.page.total);
      });
    },
    //时间
    change(date) {
      if (date && date.length > 0) {
        this.listQuery.startTime = date[0];
        this.listQuery.endTime = date[1];
      } else {
        this.listQuery.startTime = "";
        this.listQuery.endTime = "";
      }
    },
    //下载
    download(row){
      apiexportLogs.download(row.filePath)
    }
  }
};
</script>
